package com.lanou.dllo.shise.com.lanou.dllo.activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.sax.StartElementListener;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

import com.lanou.dllo.shise.R;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by dllo on 15/11/3.
 */
public class ConfigurationActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    private Button progressBtn;
    private Button examineBtn;
    private Handler handler;
    private CheckBox checkBox;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        progressBtn = (Button) findViewById(R.id.progressBtn);
        examineBtn = (Button) findViewById(R.id.examineBtn);
        checkBox = (CheckBox) findViewById(R.id.send);
        progressBtn.setOnClickListener(this);
        examineBtn.setOnClickListener(this);
        checkBox.setOnCheckedChangeListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.progressBtn:
                showProgressDialog();
                break;

            case R.id.examineBtn:
                Toast.makeText(this,"已经是最新版本啦",Toast.LENGTH_LONG).show();
                break;
            default:
                break;
        }

    }

    private void showProgressDialog() {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setMessage("正在清除缓存图片...");
        //设置进度条样式
        pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pd.setMax(100);
        pd.show();
        Thread thread = new Thread(new loadDateThreah());
        thread.start();
        handler = new Handler() {
            public void handleMessage(android.os.Message msg) {
                pd.cancel();
                Toast.makeText(ConfigurationActivity.this,"清除缓存成功",Toast.LENGTH_LONG).show();
            }
        };
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    }


    //loadDateThreah()线程类为：
        class loadDateThreah implements Runnable {
            @Override
            public void run() {
                //....这里是联网下载数据，下载完成后执行下列的方法，handlder会调用前面覆写的handleMessage方法，在那里关闭加载提示框...
                handler.sendEmptyMessageDelayed(100,2000);
            }
        }

}





